#include <iostream>
#include "rpc.pb.h"
#include "rpc.grpc.pb.h"
#include "grpc/grpc.h"
#include "grpc++/grpc++.h"
#include "grpc++/channel.h"
#include "grpc++/create_channel.h"

using namespace std;

class SVClient
{
public:
    SVClient(std::shared_ptr<grpc::Channel> channel)
        :stub_(sv::SV::NewStub(channel)) {}

    void Func1(const sv::req &req, sv::rep &rep) 
    {
        grpc::ClientContext context;
        grpc::Status status = stub_->Func1(&context, req, &rep);
        if (status.ok()) {
            cout << "Func1 ok. " << rep.ncode() << " , " << rep.smsg() << endl;
        } else {
            cout << "Func1 failed" <<endl;
        }
    }
private:
    std::unique_ptr<sv::SV::Stub> stub_;
};

int main() 
{
    cout << "rpc client start" << endl;

    SVClient client(
        grpc::CreateChannel("127.0.0.1:8000", grpc::InsecureChannelCredentials())
    );

    sv::req req;
    req.set_ncmd(0);

    sv::rep rep;

    client.Func1(req, rep);

    return 0;
}